﻿#include "socketfd.h"
#include "socketlibfunction.h"

SocketLib::SocketFD::SocketFD()
{
    _init();
}

SocketLib::SocketFD::~SocketFD()
{
    SocketLib::SocketApi::CloseSocket(m_fd);
    _init();
}

void SocketLib::SocketFD::init()
{
    _init();
}

void SocketLib::SocketFD::_init()
{
    m_fd = SOCKET_ERROR;
    m_isblocking = true;
}

void SocketLib::SocketFD::setSocketFD(sock aFD)
{
    m_fd = aFD;
}

sock SocketLib::SocketFD::getSocketFD()
{
    return m_fd;
}

void SocketLib::SocketFD::setNoBlock(bool aMode)
{
    if (isValid())
    {
        SocketApi::SetNonblock(m_fd, aMode);
    }
}

bool SocketLib::SocketFD::isValid()
{
    return SOCKET_ERROR != m_fd;
}
